package com.office.automate.dto.convertors;

import javax.servlet.http.HttpServletRequest;

import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.model.administration.Branch;
import com.office.automate.model.administration.Division;
import com.office.automate.model.administration.PublicHoliday;
import com.office.automate.model.administration.SecurityLevel;

public class AdministrationDetailConvertor {
	DataConversionUtility dataConvtionUtility = new DataConversionUtility();

	public SecurityLevel convertAddSecurityLevelDetailRequest(HttpServletRequest request) {
		SecurityLevel securityLevel = new SecurityLevel();
		securityLevel.setSecurityLevelId(dataConvtionUtility.convertStringToNumber(request.getParameter("securityLevel")));
		securityLevel.setSecurityLevelDescription(request.getParameter("roledescription"));
		return securityLevel;
	}

	public SecurityLevel convertSecurityLevelDataGridRequest(HttpServletRequest request) {
		SecurityLevel securityLevel = new SecurityLevel();
		securityLevel.setSecurityLevelId(dataConvtionUtility.convertStringToNumber(request.getParameter("Field0")));
		securityLevel.setSecurityLevelDescription(request.getParameter("Field1"));
		return securityLevel;
	}

	public Branch convertAddBranchDetailRequest(HttpServletRequest request) {
		Branch branch = new Branch();
		branch.setDescription(request.getParameter("branchdescription"));
		branch.setLocation(request.getParameter("branchlocation"));
		branch.setManagerOrSupervisorId(dataConvtionUtility.convertStringToLong(request.getParameter("managerorsupervisor")));
		return branch;
	}

	public Branch convertBranchDataGridRequest(HttpServletRequest request) {
		Branch branch = new Branch();
		branch.setBranchId(dataConvtionUtility.convertStringToNumber(request.getParameter("Field0")));
		branch.setDescription(request.getParameter("Field1"));
		return branch;
	}

	public Division convertAddDivisionDetailRequest(HttpServletRequest request) {
		Division division = new Division();
		division.setName(request.getParameter("divisionname"));
		division.setDescription(request.getParameter("divisiondescription"));
		return division;
	}

	public Division convertDivisionDataGridRequest(HttpServletRequest request) {
		Division division = new Division();
		division.setDivisionId(dataConvtionUtility.convertStringToNumber(request.getParameter("Field0")));
		division.setDescription(request.getParameter("Field1"));
		return division;
	}

	public PublicHoliday convertAddPublicHolidayDetailRequest(HttpServletRequest request) {
		PublicHoliday publicHoliday = new PublicHoliday();
		publicHoliday.setHolidayDate(dataConvtionUtility.convertToDate(request.getParameter("startyear") + "-" + request.getParameter("startmonth") + "-" + request.getParameter("startdate")));
		publicHoliday.setHolidayDescription(request.getParameter("holidaydescription"));
		publicHoliday.setHolidayType(request.getParameter("holidayType"));
		return publicHoliday;
	}
}
